package org.example.transparent;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZerlindaLi create at 2021/3/30 13:56
 * @version 1.0.0
 * @description CoursePackage
 */
public class CoursePackage extends CourseComponent{
    private List<CourseComponent> items = new ArrayList<>();
    private String name;
    private Integer level;

    public CoursePackage(String name, Integer level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public void addChild(CourseComponent catalogComponent) {
        items.add(catalogComponent);
    }

    @Override
    public void removeChild(CourseComponent catalogComponent) {
        items.remove(catalogComponent);
    }

    @Override
    public String getName(CourseComponent catalogComponent) {
        return this.name;
    }

    public void print() {
        System.out.println(this.name);
        for(CourseComponent item : items) {
            if(this.level != null){
                for(int i = 0; i < level; i++){
                    // 打印空格
                    System.out.print(" ");
                }

                for(int i = 0; i < level; i++) {
                    if(i == 0) {
                        System.out.print("+");
                    }
                    System.out.print("-");
                }
            }
            // 打印标题
            item.print();
        }
    }

}
